1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module pango.PgGlyphString;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import linker.Loader;
31 private import pango.PgFont;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * A `PangoGlyphString` is used to store strings of glyphs with geometry
38  * and visual attribute information.
39  * 
40  * The storage for the glyph information is owned by the structure
41  * which simplifies memory management.
42  */
43 public class PgGlyphString
44 {
45 	/** the main Gtk struct */
46 	protected PangoGlyphString* pangoGlyphString;
47 	protected bool ownedRef;
48 
49 	/** Get the main Gtk struct */
50 	public PangoGlyphString* getPgGlyphStringStruct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return pangoGlyphString;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected void* getStruct()
59 	{
60 		return cast(void*)pangoGlyphString;
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (PangoGlyphString* pangoGlyphString, bool ownedRef = false)
67 	{
68 		this.pangoGlyphString = pangoGlyphString;
69 		this.ownedRef = ownedRef;
70 	}
71 
72 	~this ()
73 	{
74 		if ( Linker.isLoaded(LIBRARY_PANGO[0]) && ownedRef )
75 			pango_glyph_string_free(pangoGlyphString);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return pango_glyph_string_get_type();
83 	}
84 
85 	/**
86 	 * Create a new `PangoGlyphString`.
87 	 *
88 	 * Returns: the newly allocated `PangoGlyphString`, which
89 	 *     should be freed with [method@Pango.GlyphString.free].
90 	 *
91 	 * Throws: ConstructionException GTK+ fails to create the object.
92 	 */
93 	public this()
94 	{
95 		auto __p = pango_glyph_string_new();
96 
97 		if(__p is null)
98 		{
99 			throw new ConstructionException("null returned by new");
100 		}
101 
102 		this(cast(PangoGlyphString*) __p);
103 	}
104 
105 	/**
106 	 * Copy a glyph string and associated storage.
107 	 *
108 	 * Returns: the newly allocated `PangoGlyphString`
109 	 */
110 	public PgGlyphString copy()
111 	{
112 		auto __p = pango_glyph_string_copy(pangoGlyphString);
113 
114 		if(__p is null)
115 		{
116 			return null;
117 		}
118 
119 		return ObjectG.getDObject!(PgGlyphString)(cast(PangoGlyphString*) __p, true);
120 	}
121 
122 	/**
123 	 * Compute the logical and ink extents of a glyph string.
124 	 *
125 	 * See the documentation for [method@Pango.Font.get_glyph_extents] for details
126 	 * about the interpretation of the rectangles.
127 	 *
128 	 * Examples of logical (red) and ink (green) rects:
129 	 *
130 	 * ![](rects1.png) ![](rects2.png)
131 	 *
132 	 * Params:
133 	 *     font = a `PangoFont`
134 	 *     inkRect = rectangle used to store the extents of the glyph string as drawn
135 	 *     logicalRect = rectangle used to store the logical extents of the glyph string
136 	 */
137 	public void extents(PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect)
138 	{
139 		pango_glyph_string_extents(pangoGlyphString, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect);
140 	}
141 
142 	/**
143 	 * Computes the extents of a sub-portion of a glyph string.
144 	 *
145 	 * The extents are relative to the start of the glyph string range
146 	 * (the origin of their coordinate system is at the start of the range,
147 	 * not at the start of the entire glyph string).
148 	 *
149 	 * Params:
150 	 *     start = start index
151 	 *     end = end index (the range is the set of bytes with
152 	 *         indices such that start <= index < end)
153 	 *     font = a `PangoFont`
154 	 *     inkRect = rectangle used to
155 	 *         store the extents of the glyph string range as drawn
156 	 *     logicalRect = rectangle used to
157 	 *         store the logical extents of the glyph string range
158 	 */
159 	public void extentsRange(int start, int end, PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect)
160 	{
161 		pango_glyph_string_extents_range(pangoGlyphString, start, end, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect);
162 	}
163 
164 	/**
165 	 * Free a glyph string and associated storage.
166 	 */
167 	public void free()
168 	{
169 		pango_glyph_string_free(pangoGlyphString);
170 		ownedRef = false;
171 	}
172 
173 	/**
174 	 * Given a `PangoGlyphString` and corresponding text, determine the width
175 	 * corresponding to each character.
176 	 *
177 	 * When multiple characters compose a single cluster, the width of the
178 	 * entire cluster is divided equally among the characters.
179 	 *
180 	 * See also [method@Pango.GlyphItem.get_logical_widths].
181 	 *
182 	 * Params:
183 	 *     text = the text corresponding to the glyphs
184 	 *     length = the length of @text, in bytes
185 	 *     embeddingLevel = the embedding level of the string
186 	 *     logicalWidths = an array whose length is the number of
187 	 *         characters in text (equal to `g_utf8_strlen (text, length)` unless
188 	 *         text has `NUL` bytes) to be filled in with the resulting character widths.
189 	 */
190 	public void getLogicalWidths(string text, int length, int embeddingLevel, int[] logicalWidths)
191 	{
192 		pango_glyph_string_get_logical_widths(pangoGlyphString, Str.toStringz(text), length, embeddingLevel, logicalWidths.ptr);
193 	}
194 
195 	/**
196 	 * Computes the logical width of the glyph string.
197 	 *
198 	 * This can also be computed using [method@Pango.GlyphString.extents].
199 	 * However, since this only computes the width, it's much faster. This
200 	 * is in fact only a convenience function that computes the sum of
201 	 * @geometry.width for each glyph in the @glyphs.
202 	 *
203 	 * Returns: the logical width of the glyph string.
204 	 *
205 	 * Since: 1.14
206 	 */
207 	public int getWidth()
208 	{
209 		return pango_glyph_string_get_width(pangoGlyphString);
210 	}
211 
212 	/**
213 	 * Converts from character position to x position.
214 	 *
215 	 * The X position is measured from the left edge of the run.
216 	 * Character positions are obtained using font metrics for ligatures
217 	 * where available, and computed by dividing up each cluster
218 	 * into equal portions, otherwise.
219 	 *
220 	 * <picture>
221 	 * <source srcset="glyphstring-positions-dark.png" media="(prefers-color-scheme: dark)">
222 	 * <img alt="Glyph positions" src="glyphstring-positions-light.png">
223 	 * </picture>
224 	 *
225 	 * Params:
226 	 *     text = the text for the run
227 	 *     length = the number of bytes (not characters) in @text.
228 	 *     analysis = the analysis information return from [func@itemize]
229 	 *     index = the byte index within @text
230 	 *     trailing = whether we should compute the result for the beginning (%FALSE)
231 	 *         or end (%TRUE) of the character.
232 	 *     xPos = location to store result
233 	 */
234 	public void indexToX(string text, int length, PangoAnalysis* analysis, int index, bool trailing, out int xPos)
235 	{
236 		pango_glyph_string_index_to_x(pangoGlyphString, Str.toStringz(text), length, analysis, index, trailing, &xPos);
237 	}
238 
239 	/**
240 	 * Converts from character position to x position.
241 	 *
242 	 * This variant of [method@Pango.GlyphString.index_to_x] additionally
243 	 * accepts a `PangoLogAttr` array. The grapheme boundary information
244 	 * in it can be used to disambiguate positioning inside some complex
245 	 * clusters.
246 	 *
247 	 * Params:
248 	 *     text = the text for the run
249 	 *     length = the number of bytes (not characters) in @text.
250 	 *     analysis = the analysis information return from [func@itemize]
251 	 *     attrs = `PangoLogAttr` array for @text
252 	 *     index = the byte index within @text
253 	 *     trailing = whether we should compute the result for the beginning (%FALSE)
254 	 *         or end (%TRUE) of the character.
255 	 *     xPos = location to store result
256 	 *
257 	 * Since: 1.50
258 	 */
259 	public void indexToXFull(string text, int length, PangoAnalysis* analysis, PangoLogAttr* attrs, int index, bool trailing, out int xPos)
260 	{
261 		pango_glyph_string_index_to_x_full(pangoGlyphString, Str.toStringz(text), length, analysis, attrs, index, trailing, &xPos);
262 	}
263 
264 	/**
265 	 * Resize a glyph string to the given length.
266 	 *
267 	 * Params:
268 	 *     newLen = the new length of the string
269 	 */
270 	public void setSize(int newLen)
271 	{
272 		pango_glyph_string_set_size(pangoGlyphString, newLen);
273 	}
274 
275 	/**
276 	 * Convert from x offset to character position.
277 	 *
278 	 * Character positions are computed by dividing up each cluster into
279 	 * equal portions. In scripts where positioning within a cluster is
280 	 * not allowed (such as Thai), the returned value may not be a valid
281 	 * cursor position; the caller must combine the result with the logical
282 	 * attributes for the text to compute the valid cursor position.
283 	 *
284 	 * Params:
285 	 *     text = the text for the run
286 	 *     length = the number of bytes (not characters) in text.
287 	 *     analysis = the analysis information return from [func@itemize]
288 	 *     xPos = the x offset (in Pango units)
289 	 *     index = location to store calculated byte index within @text
290 	 *     trailing = location to store a boolean indicating whether the
291 	 *         user clicked on the leading or trailing edge of the character
292 	 */
293 	public void xToIndex(string text, int length, PangoAnalysis* analysis, int xPos, out int index, out int trailing)
294 	{
295 		pango_glyph_string_x_to_index(pangoGlyphString, Str.toStringz(text), length, analysis, xPos, &index, &trailing);
296 	}
297 }